package com.yzt.zhuju.dialog;

import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.yzt.zhuju.R;
import com.yzt.zhuju.network.entity.mine.MineCardBean;
import com.yzt.zhuju.utils.SpannableFactory;
import com.yzt.p_base.AppUtils;
import com.yzt.p_base.utils.ToastUtil;

/**
 * author : bob
 * date   : 2022/12/1
 * desc   : 我的卡片分享
 */
public class MineCardDialog extends CenterBaseDialog {

    private static final String TAG = "MineCardDialog";

    private TextView tvContent;

    @Override
    public int getLayoutRes() {
        return R.layout.dialog_mine_card;
    }

    @Override
    public void bindView(View v) {

        TextView tvTitle = findViewById(R.id.tv_title);

        tvContent = findViewById(R.id.tv_content);

        MineCardBean mineCardBean = getArguments().getParcelable("extra_card");

        tvTitle.setText(SpannableFactory
                .create("You will get ")
                .append(mineCardBean.getAwardCard())
                .foregroundResColor(R.color.color_bd2ffe)
                .appendImage(R.mipmap.icon_mine_card_dialog_card_small)
                .append(" every you invite ")
                .append("1")
                .append(" friend.")
                .build());

        tvContent.setText(mineCardBean.getInvitationCode());

        findViewById(R.id.tl_send_whats).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent whatsAppIntent = new Intent(Intent.ACTION_SEND);
                whatsAppIntent.setType("text/plain");
                whatsAppIntent.setPackage("com.whatsapp");
                whatsAppIntent.putExtra(Intent.EXTRA_TEXT, tvContent.getText().toString());
                try {
                    startActivity(whatsAppIntent);
                } catch (android.content.ActivityNotFoundException ex) {
                    ToastUtil.showMessage("Whatsapp have not been installed.");
                }
            }
        });

        findViewById(R.id.tv_copy).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ClipboardManager cm = (ClipboardManager) AppUtils.getApp().getSystemService(Context.CLIPBOARD_SERVICE);
                String stringBuffer = tvContent.getText().toString();
                cm.setText(stringBuffer);
                ToastUtil.showMessage(getString(R.string.copy_success));
            }
        });
    }
}
